package com.ceshiren.hogwarts.wework;


import io.appium.java_client.android.AndroidDriver;

import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;

import org.junit.jupiter.api.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.WebDriverWait;

public class demo {


    private AndroidDriver driver;

    @BeforeEach
    public void setUp() throws MalformedURLException {
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability("platformName", "Android");
        desiredCapabilities.setCapability("noReset", "true");
        desiredCapabilities.setCapability("appPackage", "com.tencent.wework");
        desiredCapabilities.setCapability("appActivity", ".launch.WwMainActivity");
        desiredCapabilities.setCapability("deviceName", "127.0.0.1:7555");

        URL remoteUrl = new URL("http://localhost:4723/wd/hub");

        driver = new AndroidDriver(remoteUrl, desiredCapabilities);
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(60));
        WebDriverWait wait=new WebDriverWait(driver,Duration.ofSeconds(60));
        wait.until(driver->driver.findElements(By.xpath("//*[@text='通讯录']")).size()>0);
    }

    @Test
    public void demoTest() {
        driver.findElement(By.xpath("//*[@text='通讯录']")).click();
        driver.findElement(By.id("j36")).click();
        driver.findElement(By.id("en3")).click();
        driver.findElement(By.xpath("//*[@text='手动输入添加']")).click();
        driver.findElement(By.id("bf7")).sendKeys("test");
        driver.findElement(By.id("gge")).sendKeys("13560654676");
        driver.findElement(By.id("am4")).click();
        driver.findElement(By.id("j2e")).click();
        driver.findElement(By.id("j2z")).click();
        driver.findElement(By.xpath("//*[@text='消息']")).click();

    }

    @AfterEach
    public void tearDown() {
        driver.quit();
    }
}

